package com.wisezone.studentmanger.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 一、hosts文件 局域网IP映射
 *    C:\Windows\System32\drivers\etc  host
 *    
 * 二、响应服务端数据
		PrintWriter pw =  response.getWriter();
		pw.println("<h1>userName : "+userName+" , passWord:"+passWord+"</h1>");
		pw.close();

 * 三、乱码问题 
 * 
 * 请求中文乱码:
 *    GET:  server.xml->   Connector标签中添加属性: URIEncoding="UTF-8"
 *    POST: request.setCharacterEncoding("UTF-8");
 * 响应中文乱码:
 *    response.setContentType("text/html;charset=utf-8");
 * 
 */
public class MyRequestServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("doGet");
		//post请求中文乱码问题
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");//设置响应编码
		
		//接收客户端请求参数
		String userName = request.getParameter("username");
		String passWord = request.getParameter("password");
		System.out.println("userName : "+userName+" , passWord:"+passWord);

		//响应服务端数据
		PrintWriter pw =  response.getWriter();
		pw.println("<h1>userName : "+userName+" , passWord:"+passWord+"</h1>");
		pw.close();
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("doPost....");
		doGet(request, response);

	}

}
